/*
 * FileName:       N55P242.h
 * Author:         Kingsea  Version: v1.0.0  Date: 2018-11-16
 * Description:    
 * History:        
 *     <author>       <version>        <time>        <desc>
 *     Kingsea       v1.0.0        2018-11-16    
 */
#ifndef N55P242_H__
#define N55P242_H__
#ifdef __cplusplus
extern "C"{
#endif 

#define N55P__242_Dev0 0
#define N55P__242_Dev1 1

#define N55P_HIGH 1
#define N55P_LOW 0

#define N55P__242_PA    0
#define N55P__242_PB    1
#define N55P__242_PC    2

#define N55P_PIN0 0
#define N55P_PIN1 1
#define N55P_PIN2 2
#define N55P_PIN3 3
#define N55P_PIN4 4
#define N55P_PIN5 5
#define N55P_PIN6 6
#define N55P_PIN7 7

#define N55P__242_PORTAMOUNT 3
#define N55P__242_PORTPINAMOUNT 8

#define N55P_BUFA 0x00
#define N55P_BUFB 0x01
#define N55P_BUFC 0x02

#define N55P_DIRA 0x04
#define N55P_DIRB 0x05
#define N55P_DIRC 0x06

#define N55P_ATTA 0x08
#define N55P_ATTB 0x09
#define N55P_ATTC 0x0A

#define N55P_PINA 0x0C
#define N55P_PINB 0x0D
#define N55P_PINC 0x0E
#define N55P_WKCTL 0x0F


#define N55P_NBUFA 0x10
#define N55P_NBUFB 0x11
#define N55P_NBUFC 0x12

#define N55P_NDIRA 0x14
#define N55P_NDIRB 0x15
#define N55P_NDIRC 0x16

#define N55P_NATTA 0x18
#define N55P_NATTB 0x19
#define N55P_NATTC 0x1A


#define N55P_OBUFA 0x20
#define N55P_OBUFB 0x21
#define N55P_OBUFC 0x22

#define N55P_ODIRA 0x24
#define N55P_ODIRB 0x25
#define N55P_ODIRC 0x26

#define N55P_OATTA 0x28
#define N55P_OATTB 0x29
#define N55P_OATTC 0x2A


#define N55P_XBUFA 0x30
#define N55P_XBUFB 0x31
#define N55P_XBUFC 0x32

#define N55P_XDIRA 0x34
#define N55P_XDIRB 0x35
#define N55P_XDIRC 0x36

#define N55P_XATTA 0x38
#define N55P_XATTB 0x39
#define N55P_XATTC 0x3A

// Control SFR
#define N55P_CNSTA 0x40
#define N55P_CNSTB 0x41
#define N55P_CNSTC 0x42
#define N55P___NOP 0x4B
#define N55P_DVSL0 0x4C
#define N55P_DVSL1 0x4D
#define N55P_CTEST 0x4E
#define N55P_RESET 0x4F

//
#define N55P_PWMA0 0x50
#define N55P_PWMA1 0x51
#define N55P_PWMA2 0x52
#define N55P_PWMA3 0x53
#define N55P_PWMA4 0x54
#define N55P_PWMA5 0x55
#define N55P_PWMA6 0x56
#define N55P_PWMA7 0x57
#define N55P_PWMB0 0x58
#define N55P_PWMB1 0x59
#define N55P_PWMB2 0x5A
#define N55P_PWMB3 0x5B
#define N55P_PWMB4 0x5C
#define N55P_PWMB5 0x5D
#define N55P_PWMB6 0x5E
#define N55P_PWMB7 0x5F
#define N55P_PWMC0 0x60
#define N55P_PWMC1 0x61
#define N55P_PWMC2 0x62
#define N55P_PWMC3 0x63
#define N55P_PWMC4 0x64
#define N55P_PWMC5 0x65
#define N55P_PWMC6 0x66
#define N55P_PWMC7 0x67

#define N55P_PWMEA 0x78
#define N55P_PWMEB 0x79
#define N55P_PWMEC 0x7A

#define N55P_PCKAB 0x7D
#define N55P_PCKCD 0x7E


#define N55P_CKA_PA03 0x00
#define N55P_CKA_PA47 0x01
#define N55P_CKB_PB03 0x02
#define N55P_CKB_PB47 0x03
#define N55P_CKC_PC03 0x04
#define N55P_CKC_PC47 0x05

#define N55P_FOSC1    0x00
#define N55P_FOSC1_2  0x01
#define N55P_FOSC1_4  0x02
#define N55P_FOSC1_32 0x03

void    N55P_SPI_WRITE_N55P242(uint8_t u8Reg, uint8_t u8Data);
uint8_t N55P_SPI_READ_N55P242(uint8_t u8Reg);

void N55P__242_Init(uint8_t u8Dev, uint8_t sck_pin, uint8_t mosi_pin, uint8_t miso_pin, uint8_t ss_pin);

int8_t N55P_Set1PinInputFloating(uint8_t u8Port, uint8_t u8Pin);
int8_t N55P_Set1PinInputPullHigh(uint8_t u8Port, uint8_t u8Pin);
int8_t N55P_Set1PinInputPullLow(uint8_t u8Port, uint8_t u8Pin);

int8_t N55P_Set1PinHigh(uint8_t u8Port, uint8_t u8Pin);
int8_t N55P_Set1PinLow(uint8_t u8Port, uint8_t u8Pin);

int8_t N55P_Set1PinPWM(uint8_t u8Port, uint8_t u8Pin, uint8_t u8Attribut,uint8_t u8Duty);
int8_t N55P_SetPWMClkDivider(uint8_t u8Group,uint8_t u8Divider);

int8_t N55P_SetWakeupPort(uint8_t u8Port);
void N55P_ClearWakeup(void);
void N55P_StartWakeup(void);
int8_t N55P_CheckWakeupSource(uint8_t u8Port);

//////////////////////////////////////////////////////////////////////////

void N55P_ports_read(uint32_t start_port/*0~2*/, uint32_t length/*1~3*/, uint8_t * p_masks);
uint32_t N55P_pin_read(uint32_t pin_number/*0~23*/); // return 0/1
void N55P_pin_set(uint32_t pin_number);
void N55P_pin_clear(uint32_t pin_number);
void N55P_pin_toggle(uint32_t pin_number);
void N55P_cfg_output(uint32_t pin_number);
void N55P_cfg_input(uint32_t pin_number, int32_t pull_config/*0:float,1:PL,2:PH*/);

#ifdef __cplusplus
}
#endif 
#endif /* N55P242_H__ */ 

